// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_MST_WAREHOUSE
// * CreateDate    : 2012/10/29 14:55:41
// * Creater       : MstWarehouseBs
// * LastChangeDate: 2012/10/29 14:55:41
// * LastChanger   : 2012/10/29 14:55:41
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;
using ESOL.Common;

namespace ESOL.Business.Mst
{
/// <summary>
    /// MstWarehouse
    /// </summary>
    public partial class MstWarehouseBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objMstWarehouseEntity">Entity</param>
        /// <returns>Entity</returns>
        public static MstWarehouseEntity GetMstWarehouse(MstWarehouseEntity objMstWarehouseEntity)
        {
            return DataAccess.SelectSingle<MstWarehouseEntity>(objMstWarehouseEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objMstWarehouseEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertMstWarehouse(MstWarehouseEntity objMstWarehouseEntity)
        {
            return DataAccess.Insert(objMstWarehouseEntity);
        }

        public static bool InsertMstWarehouse(List<MstWarehouseEntity> objMstWarehouseEntityList)
        {
            return DataAccess.Insert(objMstWarehouseEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objMstWarehouseEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateMstWarehouse(MstWarehouseEntity objMstWarehouseEntity)
        {
            return DataAccess.Update(objMstWarehouseEntity);
        }

        public static bool UpdateMstWarehouse(List<MstWarehouseEntity> objMstWarehouseEntityList)
        {
            return DataAccess.Update<MstWarehouseEntity>(objMstWarehouseEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objMstWarehouseEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteMstWarehouse(MstWarehouseEntity objMstWarehouseEntity)
        {
            return DataAccess.Delete(objMstWarehouseEntity);
        }

        public static bool DeleteMstWarehouse(List<MstWarehouseEntity> objMstWarehouseEntityList)
        {
            return DataAccess.Delete<MstWarehouseEntity>(objMstWarehouseEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetMstWarehouseAll()
        {
            return DataAccess.SelectAllDataSet<MstWarehouseEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<MstWarehouseEntity> GetMstWarehouseAllList()
        {
            return DataAccess.SelectAll<MstWarehouseEntity>();
        }
        #endregion

        #region Functions
        public static MstWarehouseEntity GetMstWarehouseByID(string Code)
        {
            if (string.IsNullOrEmpty(Code))
                return null;
            MstWarehouseEntity m = new MstWarehouseEntity();
            m.WarehouseCode = Code;
            return DataAccess.SelectSingle<MstWarehouseEntity>(m);
        }

        public static List<MstWarehouseEntity> GetAvailableWarehouse()
        {
            MstWarehouseEntity m = new MstWarehouseEntity();
            m.DeleteFlag = 0;
            return DataAccess.Select<MstWarehouseEntity>(m);
        }

        public static DataTable GetByCondition(string condition, string orderBy, string rowCount)
        {
            string sql = CommonFunctions.GetSelect(rowCount) + @"A.* ,b.NAME_CN from dbo.MST_WAREHOUSE A left join dbo.MST_PERSON B
                            on a.MANAGER=b.PERSON_ID
                            WHERE 1=1 ";
            if (string.IsNullOrEmpty(condition) == false)
            {
                sql += condition;
            }
            if (string.IsNullOrEmpty(orderBy) == false)
            {
                sql += " ORDER BY " + orderBy;
            }
            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;
        }

        public static bool SetDeleteFlag(MstWarehouseEntity entity)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();

                    string sql = @"update MST_WAREHOUSE set DELETE_FLAG=1 where WAREHOUSE_CODE='" + entity.WarehouseCode + "'";
                    int i = broker.ExecuteSQL(sql);
                    if (i > 0)
                    {
                        return true;
                    }
                    else
                    {
                        return false;
                    }
                    broker.Commit();
                }
                catch (Exception ex)
                {
                    broker.RollBack();
                    throw ex;
                }
            }
        }

        #endregion
    }
	
	
}	

